<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
</head>

<body>
    <form id="form1">
        <div>账号：<input type="text" name="uname" autocomplete="off"></div>
        <div>密码：<input type="password" name="pwd"></div>
        <button>登录</button>
    </form>
    <script>
        $(function() {
            $("#form1").on("submit", function(e) {
                e.preventDefault()
                var uname = $("input:eq(0)").val()
                var pwd = $("input:eq(1)").val()
                $.ajax({
                    url: "http://localhotst/login",
                    method: "post",
                    data: {
                        uname: uname,
                        pwd: pwd
                    },
                    success: function(data) {
                        if (data.code == 200) {
                            location.href = "http://localhost"
                        } else {
                            alert("登陆失败")
                            location.reload()
                        }
                    }
                })
            })
        })
    </script>
</body>

</html>